package com.demo.designmode.iterator;

/**
 * @Author: jxm
 * @Description: 迭代器模式 测试
 * @Date: 2023-12-12 14:50
 * @Version: 1.0
 */
public class Client {
    public static void main(String[] args) {
        //创建聚合对象
        StudentAggregateImpl studentAggregate = new StudentAggregateImpl();
        //添加元素
        studentAggregate.addStudent(new Student("张三","001"));
        studentAggregate.addStudent(new Student("李四","002"));
        studentAggregate.addStudent(new Student("王五","003"));
        studentAggregate.addStudent(new Student("赵六","004"));

        //遍历聚合对象
        //1、获取迭代器对象
        StudentIterator iterator = studentAggregate.getStudentIterator();
        while (iterator.hasNext()){
            //2、获取元素
            Student student = iterator.next();
            System.out.println(student.toString());
        }
    }
}
